package org.hiucung.lib_base.helper

import android.content.Context
import android.media.SoundPool

/**
 * @title: SoundPoolHelper
 * @projectName OrangeAiVoiceApp
 * @description: TODO
 * @author Kicc
 * @date 2021/12/2 23:09
 */
object SoundPoolHelper {

    private lateinit var mContext: Context

    private lateinit var mSoundPool: SoundPool

    fun init(mContext: Context) {
        this.mContext = mContext
        mSoundPool = SoundPool.Builder().setMaxStreams(1).build()
    }

    fun play(resId: Int) {
        val poolId = mSoundPool.load(mContext, resId, 1)

        mSoundPool.setOnLoadCompleteListener(object : SoundPool.OnLoadCompleteListener {
            override fun onLoadComplete(soundPool: SoundPool?, sampleId: Int, status: Int) {
                if (status == 0) {
                    /*
                    int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate
                     */
                    mSoundPool.play(poolId, 1f, 1f, 1, 0, 1f)
                }
            }
        })
    }
}